# !/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2022/3/11 10:44 下午
# @Author : 曹庭
# @File : send_mail.py
# @Software: PyCharm

import smtplib
from email.mime.text import MIMEText
from email.header import Header

# 第三方 SMTP 服务
mail_host = "smtp.163.com"  # 设置服务器
mail_user = "caoting0403@163.com"  # 用户名
mail_pass = "PBKPBNDEXLCAPJVT"  # 口令

# 发送的邮箱地址
SEND_MAIL = "caoting0403@163.com"


def sendmail(share_title, share_url, share_code, receivers):
    sender = SEND_MAIL

    sharetext = '网盘链接：{}\n提取码：{}'.format(share_url, share_code)
    message = MIMEText(sharetext, 'plain', 'utf-8')
    message['From'] = Header(sender, 'utf-8')
    message['To'] = Header(receivers, 'utf-8')

    subject = share_title
    message['Subject'] = Header(subject, 'utf-8')

    try:
        smtpObj = smtplib.SMTP()
        smtpObj.connect(mail_host, 25)  # 25 为 SMTP 端口号
        smtpObj.login(mail_user, mail_pass)
        smtpObj.sendmail(sender, receivers, message.as_string())
        print("邮件发送成功")
    except smtplib.SMTPException:
        print("Error: 无法发送邮件")


if __name__ == '__main__':
    receivers = '1367446134@qq.com'  # 接收邮件，可设置为你的QQ邮箱或者其他邮箱
    share_title = "抖音视频资料视频"
    share_url = "www.baidu.com"
    share_code = "2089"
    sendmail(share_title, share_url, share_code, receivers)
